package com.huike.game.Activity;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.huike.game.R;

import androidx.appcompat.app.AppCompatActivity;

public class Game18DescImageDescActivity extends AppCompatActivity {

    private ImageView iv_left_image;
    private TextView tv_left_text;
    private TextView tv_content_title;
    private ImageView iv_rigth_image;
    private TextView tv_right_text;
    private ImageView iv_game18Desc_image;
    private LinearLayout ll_game18_move;
    private int width;
    private int height;

    private  Boolean isClick = true;

    @SuppressLint("ClickableViewAccessibility")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_game18_desc_image_desc);
        initView();

//        获取屏幕大小
//        Display display = getWindowManager().getDefaultDisplay();
//        Point point = new Point();
//        display.getSize(point);
//        width = point.x;
//        height = point.y;


        Intent intent = getIntent();
        final int image = intent.getIntExtra("image", 0);

        iv_game18Desc_image.setImageResource(image);


        //2指头触摸变大小
        iv_game18Desc_image.setOnTouchListener(new View.OnTouchListener() {

            float currentDistance ;

            float lastDistance = -1;

            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {


                if(motionEvent.getAction() == MotionEvent.ACTION_MOVE){


                    if(motionEvent.getPointerCount() >= 2){


                        float offsetX = motionEvent.getX(0) - motionEvent.getX(1);
                        float offsetY = motionEvent.getY(0) - motionEvent.getY(1);

                        currentDistance = (float) Math.sqrt(offsetX * offsetX + offsetY* offsetY);


                        if(currentDistance <0){
                            lastDistance = currentDistance;
                        }else{

                            //变大
                            if(currentDistance - lastDistance >= 5){
                                LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) iv_game18Desc_image.getLayoutParams();
                                params.width = (int) (iv_game18Desc_image.getWidth() * 1.1f);
                                params.height = (int) (iv_game18Desc_image.getHeight() * 1.1f);
                                iv_game18Desc_image.setLayoutParams(params);

                                lastDistance = currentDistance;
                                //小
                            }else if(lastDistance - currentDistance  >= 5){
                                LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) iv_game18Desc_image.getLayoutParams();
                                params.width = (int) (iv_game18Desc_image.getWidth() * 0.9f);
                                params.height = (int) (iv_game18Desc_image.getHeight() * 0.9f);
                                iv_game18Desc_image.setLayoutParams(params);
                                lastDistance =currentDistance;
                            }


                        }

                    }

                }

                return true;
            }
        });


        //单机放大变小
//        iv_game18Desc_image.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//
//                if(isClick){
//                    isClick = false;
//                    Log.e("---",isClick.toString());
//                    //放大
//                    LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) iv_game18Desc_image.getLayoutParams();
//
//                    params.width = width;
//                    params.height = height;
//
//                    iv_game18Desc_image.setLayoutParams(params);
//
//                }else{
//                    isClick = true;
//                    //缩小
//                    LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) iv_game18Desc_image.getLayoutParams();
//                    params.width = 300;
//                    params.height = 250;
//
//                    iv_game18Desc_image.setLayoutParams(params);
//
//                }
//
//            }
//        });



    }







    private void initView() {
        iv_left_image = (ImageView) findViewById(R.id.iv_left_image);
        tv_left_text = (TextView) findViewById(R.id.tv_left_text);
        tv_content_title = (TextView) findViewById(R.id.tv_content_title);
        iv_rigth_image = (ImageView) findViewById(R.id.iv_rigth_image);
        tv_right_text = (TextView) findViewById(R.id.tv_right_text);
        iv_game18Desc_image =  findViewById(R.id.iv_game18Desc_image);
        ll_game18_move =  findViewById(R.id.ll_game18_move);

        iv_rigth_image.setVisibility(View.GONE);
        tv_right_text.setVisibility(View.GONE);

        tv_content_title.setText("监控抓拍");

        iv_left_image.setImageResource(R.drawable.tiao);

        tv_left_text.setVisibility(View.GONE);

    }

    public void toPrePage(View v){
        finish();
    }
}
